package com.yl.auth.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yl.auth.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ln
 * @since 2023-07-18
 */
public interface RoleMapper extends BaseMapper<Role> {
    @Select("select role_id from user_role where user_id=#{id}")
    List<Integer> getByIdRole(@Param("id") Integer id);
    @Delete("delete from user_role where user_id=#{id}")
    void removeRole(Integer id);


    IPage<Role> findRole(Page<Role> page1);

    Role getByrole(Integer id);
    @Select("select max(id) from role")
    Integer selectMaxId();

    @Insert("insert into role_permission(permission_id,role_id)\n" +
            "values(#{id},#{rid})")
    void saverole(@Param("id") Integer id, @Param("rid")Integer rid);
    @Delete("delete from role_permission where role_id=#{id}")
    void remove(Integer id);
    @Select("select permission_id from role_permission where role_id=#{id}")
    List<Integer> getrole(Integer id);
    @Select("select a.*,COUNT(role_id) count from role a LEFT JOIN user_role b on a.id=b.role_id  where a.type=3 GROUP BY a.id order by a.id desc\n")
    IPage<Role> getAll(Page<Role> page1);
    @Delete("delete from role_permission where role_id=#{id}")
    void deleteRolePermission(Integer id);
    @Select("select * from role where type=3")
    List<Role> getAllByType();
    @Select("select * from role where id=")
    Role getUserId(Integer usersId);
    @Update("update role set is_delete=1 where id=#{id}")
    void updaterole(Integer id);
    @Select("select * from role where type=1")
    List<Role> listrole();
    @Select("SELECT * from role_permission where role_id = #{id}")
    List<Role> quanxianList(Long id);
    @Delete("delete from role where id=#{id}")
    void removeByDelId(Integer id);
}
